{include file="head" /}

{include file="menu" /}
<!--main content start-->
      <section id="main-content">
          <section class="wrapper">
              
            
          <div class="row">
                  <div class="col-sm-8">
                      <section class="panel">
                          <header class="panel-heading">
                              <h4 class="left">栏目管理</h4> 
                              <a href="javascript:;" onclick="addclass()"><span class="btn right btn-primary">添加栏目+</span></a>
                              <br><br>
                          </header>
                          <table class="table">
                              <thead>
                              <tr>
                                  <th>编号</th>
                                  <th>标题</th>
                                  <th>操作</th>
                                  
                              </tr>
                              </thead>
                              <tbody>
                              <!-- {volist id="vo" name="newsclass"} -->
                              <tr>
                                  <td>{$vo.fid}</td>
                                  <td>{$vo.fclass}</td>
                                  <td> 
                                      <button class="btn btn-primary btn-xs" onclick="editclass('{$vo.fid}','{$vo.fclass}')"><i class="icon-pencil"></i></button>
                                      <button class="btn btn-danger btn-xs" onclick="deleteclass('{$vo.fid}')"><i class="icon-trash "></i></button>
                                  </td>
                                  
                              </tr>
                              <!-- {/volist} -->
                              </tbody>
                          </table>
                      </section>
                  </div>
          </div>       
          <div  class="row editadd" style="display:none">
            <div class="col-lg-8">
                <section class="panel">
                  
                  <div class="panel-body bio-graph-info">
                      <h1 class="f_title"></h1>
                      <form class="form-horizontal" role="form" method="post" id="formid">
                          
                          <div class="form-group">
                              <label  class="col-lg-2 control-label">栏目名称</label>
                              <div class="col-lg-6">
                                  <input type="text" class="form-control" id="f-name" name="fclass" placeholder=" " value="">
                                  <input type="hidden" value="" name="id" id="f-id">
                              </div>
                          </div>
                         
                          <div class="form-group">
                              <div class="col-lg-offset-2 col-lg-10">
                                  <input type="submit" onclick="return formeidt(this.form)" class="btn btn-success" value="保存">
                              </div>
                          </div>
                      </form>
                  </div>
              </section> 
            </div>
          </div>
          
             

          </section>
      </section>
      <!--main content end-->
  </section>
{include file="foot" /}
<script>

	//eidt class
	function editclass(id,data){
		$('.editadd').show();
		$('.f_title').html('编辑栏目');
		$('#f-name').val(data);
		$('#f-id').val(id);
	}

	//add class
	function addclass(){
		$('.editadd').show();
		$('.f_title').html('添加栏目');
		$('#f-name').val('');
		$('#f-id').val('');
	}

	//delete class
	function deleteclass(id){
		layer.open({
		  content: '确定删除吗',
		  yes: function(index){
		    //do something
		    var url = "{:url('index/deleteclass')}"+"?id="+id;
		    
		    $.get(url,function(data){
		    	if (data.type == 1) {
		          layer.msg(data.data, {icon: 1,time: 1000},function(){
		            window.location.href="{:Url('admin/index/contentclass')}";
		          }); 

		        }else if(data.type == -1){
		          layer.msg(data.data, {icon: 2}); 
		        }
		    });
		  }
		});
	}

  //eidt or add one class
  function formeidt(form){
    $fclass = form.fclass.value;
    if(!$fclass){
      layer.msg('请输写栏目名称'); 
        return false;
    }

    var formurl = "{:Url('index/editclass')}"
    var data = $('#formid').serialize();
    $.post(formurl,data,function(data){
      if (data.type == 1) {

        layer.msg(data.data, {icon: 1,time: 1000},function(){
          window.location.href="{:Url('admin/index/contentclass')}";
        }); 

      }else if(data.type == -1){
        layer.msg(data.data, {icon: 2}); 
      }

    });

    return false;

  }


	
</script>